<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive,defineProps,onMounted } from 'vue'
import systemDeptAddress from '@/api/system/systemDeptAddress'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const props = defineProps({
  fromData:{
    default: {},
  }
})
onMounted(()=>{
  crudRef.value.requestData()
})
const numberOperation = (newValue, id, numberName) => {
  systemDeptAddress.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemDeptAddress.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_system_dept_address',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  autoRequest:false,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemDeptAddress.getList,
  recycleApi: systemDeptAddress.getRecycleList,
  add: {
    show: true,
    api: systemDeptAddress.save,
    auth: ['system:deptAddress:save']
  },
  edit: {
    show: true,
    api: systemDeptAddress.update,
    auth: ['system:deptAddress:update']
  },
  delete: {
    show: true,
    api: systemDeptAddress.deletes,
    auth: ['system:deptAddress:delete'],
    realApi: systemDeptAddress.realDeletes,
    realAuth: ['system:deptAddress:realDeletes']
  },
  recovery: {
    show: true,
    api: systemDeptAddress.recoverys,
    auth: ['system:deptAddress:recovery']
  },
  import: {
    show: true,
    url: 'system/deptAddress/import',
    templateUrl: 'system/deptAddress/downloadTemplate',
    auth: ['system:deptAddress:import']
  },
  export: {
    show: true,
    url: 'system/deptAddress/export',
    auth: ['system:deptAddress:export']
  },
  beforeRequest:(params)=>{
    params.dept_id = props.fromData.id
  },
  beforeAdd:(formData)=>{
    formData.dept_id = props.fromData.id
    return true
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "配送公司",
    dataIndex: "dept_id",
    formType: "select",
    search: true,
    addDisplay:false,
    editDisabled:true,
    dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				remote: "system/dept/remote",
				// 指定组件接收的props
				props: { label: "name", value: "id" },
				// 开启分页
				// 远程请求配置项
        openPage:false,
				remoteOption: {
					// 设置查询的字段
					select: ["id", "name"],
          filter: {
            type: [ '=', 3 ],
            status: ['=',1]
          },
					// 关联模型
					relations: [],
          
				},

        translation: true
		},
  },
  {
    title: "管辖区",
    dataIndex: "guanxiaqu",
    formType: "select",
    search: true,
    dict: {
            name: "guanxiaqu",
            props: {
                label: "title",
                value: "key",
            },
            translation: true,
        },
    commonRules: {
      required: true,
      message: "请选择管辖区"
    }
  },
  {
    title: "送达地",
    dataIndex: "daodadi",
    formType: "select",
    search: true,
    dict: {
            name: "daodadi",
            props: {
                label: "title",
                value: "key",
            },
            translation: true,
        },
    commonRules: {
      required: true,
      message: "请选择送达地"
    }
  },
  {
    title: "运输方式",
    dataIndex: "transport_type",
    formType: "select",
    search: true,
    dict: {
            name: "transport_type",
            props: {
                label: "title",
                value: "key",
            },
            translation: true,
        },
    commonRules: {
      required: true,
      message: "请选择运输方式"
    }
  },
  {
    title: "始发地",
    dataIndex: "shifadi",
    formType: "input",
    search: true
  },
  {
    title: "里程",
    dataIndex: "licheng",
    formType: "input",
    search: true
  },
  // {
  //   title: "品名",
  //   dataIndex: "goods_id",
  //   formType: "select",
  //   search: true,
  //   virtualListProps:{
  //     height:200
  //   },
  //   dict: {
	// 			// 远程通用接口请求，新版代码生成都有一个 remote 接口
	// 			url: "goods/manage/index",
	// 			method:'GET',
	// 			// 指定组件接收的props
	// 			props: { label: "name", value: "id" },
	// 			// 开启分页
	// 			// 远程请求配置项
  //       params:{
  //         pageSize:10000
  //       },
	// 			remoteOption: {
	// 				// 设置查询的字段
	// 				select: ["id", "name"],
	// 				// 关联模型
	// 				relations: [],
	// 			},
  //       translation: true
	// 	},
  //   commonRules: {
  //     required: true,
  //     message: "请选择品名"
  //   }
  // },
  // {
  //   title: "控制价",
  //   dataIndex: "kongzhi_price",
  //   formType: "input",
  //   search: true
  // },
  // {
  //   title: "中标价",
  //   dataIndex: "zhongbiao_price",
  //   formType: "input",
  //   search: true
  // },
  {
    title: "执行价",
    dataIndex: "zhixing_price",
    formType: "input",
    search: true
  },
  {
    title: "单位",
    dataIndex: "unit_id",
    formType: "select",
    search: true,
    virtualListProps:{
      height:200
    },
    dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				url: "financial/unit/index",
				method:'GET',
				// 指定组件接收的props
				props: { label: "name", value: "id" },
				// 开启分页
				// 远程请求配置项
        params:{
          pageSize:100
        },
				remoteOption: {
					// 设置查询的字段
					select: ["id", "name"],
					// 关联模型
					relations: [],
				},
        translation: true
		},
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'system:deptAddress' } </script>